package com.yuwei.module_sign.adapter

import android.graphics.Color
import com.bw.lib_http.entity.SignListEntityItem
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.yuwei.module_sign.R
import java.text.SimpleDateFormat

class AttendanceAdapter :BaseQuickAdapter<SignListEntityItem,BaseViewHolder>(R.layout.attendance_item) {
    override fun convert(holder: BaseViewHolder, item: SignListEntityItem) {
        val time = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
        val time1 = SimpleDateFormat("yyyy 年 MM 月 dd 日")
        val time2 = SimpleDateFormat("HH:mm:ss")
        if (item.status == "1"){
            val format = time1.format(time.parse(item.morningCheckIn))
            val format1 = time2.format(time.parse(item.morningCheckIn))
            val format2 = time2.format(time.parse(item.afternoonCheckIn))
            holder.setText(R.id.attendance_time,format.toString())
            holder.setText(R.id.attendance_type,"正常")
                .setTextColor(R.id.attendance_type,Color.parseColor("#8CD768"))
                .setBackgroundResource(R.id.attendance_type,R.drawable.minutes_type_bg1)
            holder.setText(R.id.attendance_sb_time,"上班:"+format1+"-下班:"+format2)
            holder.setText(R.id.attendance_sb_dz,item.location)

        }
        if (item.status == "2"){
            val format = time1.format(time.parse(item.morningCheckIn))
            val format1 = time2.format(time.parse(item.morningCheckIn))
            val format2 = time2.format(time.parse(item.afternoonCheckIn))
            holder.setText(R.id.attendance_time,format.toString())
            holder.setText(R.id.attendance_type,"迟到")
                .setTextColor(R.id.attendance_type,Color.parseColor("#FFC107"))
                .setBackgroundResource(R.id.attendance_type,R.drawable.minutes_type_bg2)
            holder.setText(R.id.attendance_sb_time, "上班:$format1-下班:$format2")
            holder.setText(R.id.attendance_sb_dz,item.location)
        }
        if (item.status == "3"){
            val format = time1.format(time.parse(item.morningCheckIn))
            val format1 = time2.format(time.parse(item.morningCheckIn))
            val format2 = time2.format(time.parse(item.afternoonCheckIn))
            holder.setText(R.id.attendance_time,format.toString())
            holder.setText(R.id.attendance_type,"早退")
                .setTextColor(R.id.attendance_type,Color.parseColor("#2196F3"))
                .setBackgroundResource(R.id.attendance_type,R.drawable.minutes_type_bg3)
            holder.setText(R.id.attendance_sb_time,"上班:"+format1+"-下班:"+format2)
            holder.setText(R.id.attendance_sb_dz,item.location)
        }
        if (item.status == "4"){
            val format = time1.format(time.parse(item.morningCheckIn))
            val format1 = time2.format(time.parse(item.morningCheckIn))
            val format2 = time2.format(time.parse(item.afternoonCheckIn))
            holder.setText(R.id.attendance_time,format.toString())
            holder.setText(R.id.attendance_type,"缺勤")
                .setTextColor(R.id.attendance_type,Color.parseColor("#E91E63"))
                .setBackgroundResource(R.id.attendance_type,R.drawable.minutes_type_bg4)
            holder.setText(R.id.attendance_sb_time, "上班:$format1-下班:$format2")
            holder.setText(R.id.attendance_sb_dz,item.location)
        }
    }
}